package senpec.qc.harmony.system.permission;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import senpec.qc.harmony.base.mybatisplus.IBaseControllerImpl;
import senpec.qc.harmony.base.mybatisplus.Result;

import java.util.List;

@RestController
@RequestMapping("/system/permission")
@Slf4j
public class PermissionController extends IBaseControllerImpl<Permission, PermissionService> {
    private final PermissionService permissionService;

    public PermissionController(PermissionService baseService, PermissionService permissionService) {
        super(baseService);
        this.permissionService = permissionService;
    }

    @GetMapping("/userId/{userId}")
    public Result<List<String>> getPermissionTextListByUserId(@PathVariable Long userId) {
        return permissionService.getPermissionTextListByUserId(userId);
    }

    //当进行权限操作时执行该操作
    @PutMapping("/resetPermissionListByRoleAndMenu")
    public Result<?> resetPermissionListByRoleAndMenu(PermissionDTO permissionDTO) {
        return permissionService.resetPermissionListByRoleAndMenu(permissionDTO);
    }

    @PostMapping("/selectPermissionTextListByRoleNameAndMenuTitle")
    public Result<List<String>> selectPermissionTextListByRoleNameAndMenuTitle(PermissionDTO permissionDTO) {
        return permissionService.selectPermissionTextListByRoleNameAndMenuTitle(permissionDTO);
    }

    @PostMapping("/selectPermissionListByRoleNameAndMenuTitle")
    public Result<List<Permission>> selectPermissionListByRoleNameAndMenuTitle(PermissionDTO permissionDTO) {
        return permissionService.selectPermissionListByRoleNameAndMenuTitle(permissionDTO);
    }
}